/**
 * 项目状态判断工具函数
 *
 * @author LUSH
 * @date 2025-01-27
 */

// 项目审核状态常量
export const APPROVE_STATUS = {
  NOT_SUBMITTED: '0', // 未提交
  SUBMITTED: '1', // 已提交
  IN_PROGRESS: '2', // 审核中
  APPROVED: '3', // 审核通过
  REJECTED: '4', // 审核拒绝
  CANCELLED: '5', // 已撤销
  IMPORTED: '6' // 已导入
} as const;

/**
 * 判断项目状态是否可以删除
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function canDelete(commitStatus: string | undefined): boolean {
  return (
    commitStatus === APPROVE_STATUS.NOT_SUBMITTED ||
    commitStatus === APPROVE_STATUS.SUBMITTED ||
    commitStatus === APPROVE_STATUS.CANCELLED ||
    commitStatus === APPROVE_STATUS.IMPORTED
  );
}

/**
 * 判断项目状态是否可以添加或修改
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function canAddOrEdit(commitStatus: string | undefined): boolean {
  return (
    commitStatus === APPROVE_STATUS.NOT_SUBMITTED ||
    commitStatus === APPROVE_STATUS.SUBMITTED ||
    commitStatus === APPROVE_STATUS.CANCELLED ||
    commitStatus === APPROVE_STATUS.IMPORTED ||
    commitStatus === APPROVE_STATUS.REJECTED
  );
}

/**
 * 判断项目状态是否可以导入数据
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function canImport(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.NOT_SUBMITTED || commitStatus === undefined || commitStatus === null || commitStatus === '';
}

/**
 * 判断项目状态是否可以提交审核
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function canSubmit(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.NOT_SUBMITTED || commitStatus === APPROVE_STATUS.REJECTED || commitStatus === APPROVE_STATUS.CANCELLED;
}

/**
 * 判断项目状态是否可以撤销
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function canCancel(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.SUBMITTED || commitStatus === APPROVE_STATUS.IN_PROGRESS;
}

/**
 * 判断项目状态是否为审核中状态
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function isInProgress(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.SUBMITTED || commitStatus === APPROVE_STATUS.IN_PROGRESS;
}

/**
 * 判断项目状态是否为已完成状态（审核通过或拒绝）
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function isCompleted(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.APPROVED || commitStatus === APPROVE_STATUS.REJECTED;
}

/**
 * 判断项目状态是否为审核通过
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function isApproved(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.APPROVED;
}

/**
 * 判断项目状态是否为审核拒绝
 *
 * @param commitStatus 项目状态
 * @returns 判断结果
 */
export function isRejected(commitStatus: string | undefined): boolean {
  return commitStatus === APPROVE_STATUS.REJECTED;
}

/**
 * 获取项目状态描述
 *
 * @param commitStatus 项目状态
 * @returns 状态描述
 */
export function getStatusDescription(commitStatus: string | undefined): string {
  const statusDescriptions: Record<string, string> = {
    [APPROVE_STATUS.NOT_SUBMITTED]: '未提交',
    [APPROVE_STATUS.SUBMITTED]: '已提交',
    [APPROVE_STATUS.IN_PROGRESS]: '审核中',
    [APPROVE_STATUS.APPROVED]: '审核通过',
    [APPROVE_STATUS.REJECTED]: '审核拒绝',
    [APPROVE_STATUS.CANCELLED]: '已撤销',
    [APPROVE_STATUS.IMPORTED]: '已导入'
  };

  return statusDescriptions[commitStatus || ''] || '未知状态';
}

export default {
  APPROVE_STATUS,
  canDelete,
  canAddOrEdit,
  canImport,
  canSubmit,
  canCancel,
  isInProgress,
  isCompleted,
  isApproved,
  isRejected,
  getStatusDescription
};
